<ul class="breadcrumb">
  <li><a href="/">首页</a> <span class="divider">/</span></li>
  <li><a href="/exams">考试信息</a> <span class="divider">/</span></li>
  <li><%= link_to @f_t.title, @f_t %>
    <span class="divider">/</span></li>
  <li class="active"><%=
      if @f_n ==""
          "所有成绩信息"
      else
          @f_n
      end
  %></li>
</ul>
<div class="alert-message warning">
  <a class="close" href="#">×</a>

  <p> <%= @pp %>人及格 <%= @np %>人不及格 平均分:<%= @pj %></p>
</div>
<p>
  <a style="cursor: pointer;text-decoration: underline" onclick="disable_input()">录入/更改成绩</a> |
  <a style="cursor: pointer;text-decoration: underline" onclick="submit_mark()">提交更改</a> |
  <a style="cursor: pointer;text-decoration: underline" onclick="$('.filter').toggle('slow')">选择过滤条件</a> |
  <a style="cursor: pointer;text-decoration: underline" href="/scores?eid=<%= @f_t.id %>">重置过滤条件</a>
<script type="text/javascript">
    var isLoading = false;
    var ismark = true;
    function disable_input() {
        if (ismark) {
            $('.marktd').each(function() {
                var html = "<input class=\"markv\" id=\"" + $(this).attr('id') + "\" value=\"" + $(this).html() + "\" type=\"text\" style=\"height: 15px; margin:2px 0 0 5px ; width : 30px;\"/>";
                $(this).html(html);
                $(this).children().attr('onkeyup', "value=value.replace(/[^\\d]/g,'')").attr("onbeforepaste", "clipboardData.setData('text',clipboardData.getData('text').replace(/[^\\d]/g,''))");
                $(this).css('padding', '0');
            });
            ismark = false;
        } else {
            $('.marktd').each(function() {
                $(this).html($(this).children().val());
                $(this).css('padding', '6px 6px 6px');
            });
            ismark = true;
        }
    }
    function submit_mark() {
        var v = "";
        $(".markv").each(function() {
            v += $(this).attr("id") + ":" + $(this).val() + "|";
        });

        if (isLoading) {
            return;
        }
        isLoading = true;
        jQuery.ajax({
            url : "/submitmark",
            dataType : "html",
            timeout : 5000,
            type:"POST",
            data : {
                marks:v
            }
            ,
            success : function(data) {
                if (data == "success") {
                    alert("更新成功");
                    document.location.reload();
                } else {
                    alert("更新失败,请重试");
                }
            }
            ,
            error : function(jqXHR, textStatus, errorThrown) {
                alert("程序出错,请重试")
            }
            ,
            complete : function() {
                isLoading = false;
            }
        });

    }
</script>
<div class="filter" style="display: none;">
  <form action="/scores">
    <p>分数大于(>)<input type="text" name="dy" onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" size="1"/>
      分数小于(<)<input type="text" name="xy" onkeyup="value=value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" size="1"/>
    </p>

    <p>
      <input type="hidden" name="eid" value="<%= @f_t.id %>"/>
      <input type="hidden" name="type" value="s"/>
      大学:<%= select_tag "u", options_from_collection_for_select(Student.select("DISTINCT(university)"), "university", "university"), :multiple => true, :size=>4 %>&nbsp;
      院系:<%= select_tag "y", options_for_select([]), :multiple => true, :size=>4 %>&nbsp;
      分组:<%= select_tag "g", options_from_collection_for_select(Student.select("DISTINCT(sgroup)"), "sgroup", "sgroup"), :multiple => true, :size=>4 %>&nbsp;
    </p>
    <input type="submit" value="提交"/>
  </form>
</div>
<script type="text/javascript">
    $("#u").change(function() {
        var v = "";
        $('option:selected', this).each(function() {
            v += ("," + this.value);
        });
        if (v == "") {
            $("#y").html("");
            return;
        }
        jQuery.ajax({
            url : "/get_college_by_university",
            dataType : "html",
            timeout : 1000,
            data : {
                content : v
            }
            ,
            success : function(data) {
                $("#y").html(data);
            }
            ,
            error : function(jqXHR, textStatus, errorThrown) {
                alert("程序出错,请重试")
            }
            ,
            complete : function() {
                isLoading = false;
            }
        });
    });

    $(document).ready(function() {
                $("table").tablesorter({
                    sortList: [
                        [7,1]
                    ]
                });
            }
    );
</script>
<table class="zebra-striped bordered-table">
  <thead>
  <tr>
    <th>学号</th>
    <th>姓名</th>
    <th>年级</th>
    <th>学校</th>
    <th>学院</th>
    <th>专业</th>
    <th>分配班级</th>
    <th>分数</th>
  </tr>
  </thead>
  <tbody>
  <% @scores.each do |score| %>
      <tr class="<%= !score.mark.nil? && score.mark>=60 ? "y" :"n" %>">
        <td><%= score.student.studentId %></td>
        <td><%= score.student.name %></td>
        <td><%= score.student.grade %></td>
        <td><%= score.student.university %></td>
        <td><%= score.student.college %></td>
        <td><%= score.student.major %></td>
        <td><%= score.student.sgroup %></td>
        <td class="marktd" id="<%= score.id %>"><%= score.mark %></td>
      </tr>
  <% end %>
  </tbody>
</table>
<!--<%= link_to 'New Score', new_score_path %>-->